<!--processed-->
<link rel="stylesheet" href="/views/img/tmp.css">
<section id="img">
    <div class="breadcrumb">
        <i class="back iconfont icon-fanhui1" id="back"></i>
        <span>Resolution</span>
        <span class="interval">/</span>
        <span>Inquiry</span>
    </div>
    <div class="layout-processed feat-grid">
        <div class="header fx-col-c">
            <form id="form" action="" class="row">

                <div class="col-sm-5 col-sm-offset-1">
                    <div class="search-a fx-row-b">
                        <i id="searchBtn" class="iconfont icon-sousuo"></i>
                        <input name="content" type="text" placeholder="请输入交易号">
                    </div>
                </div>
                <div class="col-sm-3">
                    <button id="check" type="button" class="btn-e ml20">
                        <i class="send-animate"><span class="send-main"></span></i>
                        <span class="send-text">查询</span>
                    </button>
                </div>
            </form>
        </div>

        <div class="data-box">
            <div class="row">
                <div class="col-sm-8">
                    <div class="box-img">
                        <div class="img-title">ERP订单详情图片</div>
                        <div class="img-content fx-row-s">
                            <img class="previewImg" data-link="" data-name="orderImg" src="" alt="">
                            <a data-name="orderImgLink" href="" target="_blank">下载</a>
                        </div>
                    </div>
                </div>
                <div class="col-sm-8">
                    <div class="box-img">
                        <div class="img-title">Return Policy</div>
                        <div class="img-content fx-row-s">
                            <img class="previewImg" data-name="returnPolicy" data-link="https://www.allindesk.com/img/Return%20Policy.png" src="https://www.allindesk.com/img/Return%20Policy.png" alt="">
                            <a data-name="returnPolicyLink" href="https://www.allindesk.com/img/Return%20Policy.png" target="_blank">https://www.allindesk.com/img/Return%20Policy.png</a>
                        </div>
                    </div>
                </div>

            </div>
            <!--物流-->
            <div data-name="logistics" class="row">

            </div>
            <div data-name="erpBox" class="row">

            </div>
        </div>

    </div>
    <footer class="footer fx-row-b hide">
        <div>
            <span>Showing <span id="page-start">1</span> to <span id="page-end">20</span> of <span id="page-total">0</span> entries</span>
            <select name="page">
                <option value="10">10</option>
                <option value="20">20</option>
                <option value="30">30</option>
                <option value="50">50</option>
                <option value="100">100</option>
            </select>
            <span>records per page</span>
        </div>
        <section id="box-page"></section>
    </footer>
</section>

<!--站点列表-->
<script id="inquiry-site-list" type="text/html">
    {{each data as v i}}
    <li data-val="{{v.pp_merchant_id}}" class="sel-list">{{v.site_name}}</li>
    {{/each}}
</script>


<!--图片预览模板-->
<script id="img-preview" type="text/html">
    <div class="media">
        <embed class="preview hide" src="" type="">
        <img class="preview hide" src="" alt="">
    </div>
</script>

<!--图片物流模板-->
<script id="img-express-list" type="text/html">
    {{each list as v i}}
        {{if(v.queryErp == 'success')}}
        <div class="col-sm-8">
            <div class="box-img">
                <div class="img-title">tracking information</div>
                <div class="img-content fx-row-s">
                    <img class="previewImg" data-link="{{ $imports.p.req(v.url) }}" data-name="tracking" src="{{ $imports.p.req(v.url) }}" alt="">
                    <a data-name="trackingLink" href="{{ $imports.p.req(v.url) }}" target="_blank">{{ $imports.p.req(v.url) }}</a>
                </div>
            </div>
        </div>
        {{/if}}
    {{/each}}
</script>

<!--面单(保留未使用)-->
<script id="img-erp-list" type="text/html">
    {{each list as v i}}
        {{if(v.expressNo)}}
        <div class="col-sm-8">
            <div class="box-img">
                <div class="img-title">ERP shipping面单 <button class="previewImg preview-button hide"  data-link="http://api-erp.orderplus.com/api/order/DownLoadDeliverySheetPhoto?trakcingNumber={{v.expressNo}}" src="http://api-erp.orderplus.com/api/order/DownLoadDeliverySheetPhoto?trakcingNumber={{v.expressNo}}" data-name="erpShipping">预览</button></div>
                <div class="img-content fx-row-s">
                    <!--<img class="previewImg" data-name="erpShipping" src="https://ups.aopcdn.com/s1626/common/18082/32u9635fb215fb1483db646f0904f4660d8.png" alt="">-->
                    <!--<embed class="previewImg" data-link="" data-name="erpShipping" src="http://api-erp.orderplus.com/api/order/DownLoadDeliverySheetPhoto?trakcingNumber={{v.expressNo}}" type="">-->
                    <a data-name="erpShippingLink" href="http://api-erp.orderplus.com/api/order/DownLoadDeliverySheetPhoto?trakcingNumber={{v.expressNo}}" target="_blank">http://api-erp.orderplus.com/api/order/DownLoadDeliverySheetPhoto?trakcingNumber={{v.expressNo}}</a>
                </div>
            </div>
        </div>
        {{/if}}
    {{/each}}
</script>

<!--面单(正在使用)-->
<script id="img-erp-list2" type="text/html">
    {{each data as v i}}
    <div class="col-sm-8">
        <div class="box-img">
            <div class="img-title">ERP shipping面单 <button class="previewImg preview-button"  data-link="{{v}}" src="{{v}}" data-name="erpShipping">预览</button></div>
            <div class="img-content fx-row-s">
                <!--<img class="previewImg" data-name="erpShipping" src="https://ups.aopcdn.com/s1626/common/18082/32u9635fb215fb1483db646f0904f4660d8.png" alt="">-->
                <embed class="previewImg" data-link="" data-name="erpShipping" src="{{v}}" type="">
                <a data-name="erpShippingLink" href="{{v}}" target="_blank">{{v}}</a>
            </div>
        </div>
    </div>
    {{/each}}
</script>

<!-- js -->
<script>

    $.extend(window.p,{
        page:1,
        num:20,
        total:0,
        pageObj:null,
        data:{},
        layerObj:null,
        transaction_id:'',//8UC17485904176704
        pdf:'https://ups.aopcdn.com/s1626/common/18082/32u9635fb215fb1483db646f0904f4660d8.png',
        logistics:null,
        req:function(url){
            var path = com.getEnv();
            if(path == 'dev'){
                base = "https://api.beta.allindesk.com";
            }else if(path == 'testing'){
                base = "https://api.beta.allindesk.com";
            }else if(path == 'production'){
                base = "https://api.allindesk.com"
            }
            return base + url + "&date=" + new Date().getTime();
        }
    });

    template.defaults.imports.app = app;
    template.defaults.imports.p = p;

    $(function(){

        init();

        function init(){

            if(p.urlPara){
                p.transaction_id = p.urlPara;
            }
            renderImg();

            //返回
            $(".back").click(function(){
                window.history.go(-1);
            });

            //初始化选项
            $("[data-name='transaction_type']").comSelect({init:true,});

            $(".data-box").on('click',".previewImg",function(){
                var src = $(this).attr('src');
                var link = $(this).attr('data-link');
                var labelType = $(this)[0].nodeName;
                alertLayer(src,labelType)
            });

            $("#check").on('click',function(){
                var content = $("input[name='content']").val();
                if(content){
                    $(this).addClass('active-animate').prop('disabled',true);
                    renderImg(content);
                }else{
                    $.comMessage({
                        type:'prompt',
                        text:'请输入交易号！',
                    });
                }
            });
        }

        function alertLayer(url,labelType){
            var dom = $("#img-preview").html();
            p.layerObj = new ComLayer({
                title:'证据预览',
                dom:dom,
                width:'85%',
                okHandler:function(){
                  p.layerObj.close();
                },
                callback:function(){
                    $(".preview").attr('src',url);
                    if(labelType == 'IMG'){
                        $("img.preview").removeClass('hide');
                    }else{
                        $("embed.preview").removeClass('hide');
                    }
                },
            })
        }


        function renderImg(id){
            id ? p.transaction_id = id : '';
            clearImg();
            if(p.transaction_id){
                requestOrder();
                requestExpress();
            }
        }

        //请求面单(正在使用)
        function reqErp(){
            if(p.logistics.list.length>=1){
                var arr = p.logistics.list.map(function(item,index){
                    if(item.expressNo){
                        return item.expressNo;
                    }
                });
                if(!arr.length){return;}
                app.ajax({
                    type:'post',
                    data:{
                        expresses:arr
                    },
                    url:app.api('/api/erp/downloadErpFaceSheet'),
                    success:function(res){
                        if(res.code == 0){
                            var dom = template('img-erp-list2',res);
                            $("[data-name='erpBox']").html(dom);
                        }else{
                            setTimeout(function(){
                                $.comMessage({
                                    type:'warning',
                                    text:res.msg,
                                });
                            },5000)
                        }
                    },
                    complete:function(){
                        $("#check").removeClass('active-animate').prop('disabled',false);
                    }
                });
            }

        }

        //请求面单(保留未使用)
        function requestErp(){
            if(p.logistics.list.length>=1){
                var dom = template('img-erp-list',p.logistics);
                $("[data-name='erpBox']").html(dom);
            }
        }
        //请求订单
        function requestOrder(){
            console.log('订单列表');
            var orderImg = p.req('/api/getErpOrderScreenshotController/getScreenshotByTx?tx=' + p.transaction_id);
            var orderImgLink =  p.req('/api/getErpOrderScreenshotController/getScreenshotByTx?tx=' + p.transaction_id);
            $("[data-name='orderImg']").attr('src',orderImg);
            $("[data-name='orderImgLink']").attr('href',orderImgLink).html(orderImgLink);
        }
        //请求物流列表
        function requestExpress(){
            console.log('express物流列表');
            app.ajax({
                type:'get',
                //url:'http://api.beta.allindesk.com/api/getErpOrderScreenshotController/getAllExpressByTx?tx=a639d8acb6b24a2b923c8f0191c0d7b0',
                url:app.api('/api/ai/getAllExpressByTx/' + p.transaction_id),
                success:function(res){
                    if(res.success){
                        var dom = template('img-express-list',res);
                        $("[data-name='logistics']").html(dom);
                        p.logistics = res;
                        //requestErp();
                        if(isExpress()){
                            $.comMessage({
                                type:'warning',
                                text:'No query for logistics information, please check in other channels！',
                                time:10000
                            });
                        }

                        reqErp();
                    }else{
                        $.comMessage({
                            type:'warning',
                            text:res.msg,
                        });
                        $("#check").removeClass('active-animate').prop('disabled',false);
                    }
                },
                error:function(){
                    $("#check").removeClass('active-animate').prop('disabled',false);
                }
            });
        }

        //是否拥有物流
        function isExpress(){
            var isTrue = true;
            $.each(p.logistics.list,function(index,item){
                if(item.queryErp == 'success'){
                    isTrue = false;
                    return false;
                }
            })
            return isTrue;
        }

        //清除当前数据
        function clearImg(){
            //订单详情
            $("[data-name='orderImg']").attr('src','');
            $("[data-name='orderImgLink']").attr('href','').html('');

            //物流相关
            $("[data-name='tracking']").attr('src','');
            $("[data-name='trackingLink']").attr('href','').html('');
            $("[data-name='logistics']").html('');

            //面单
            $("[data-name='erpShipping']").attr('src','');
            $("[data-name='erpShippingLink']").attr('href','').html('');
            $("[data-name='erpBox']").html('');
        }

        function typeFile(str){
            if(/\.pdf/g.test(str)){
                return 'pdf'
            }else{
                return 'img'
            }
        }


        //获取列表参数
        function getPara(){
            $.each($("#form").serializeArray(),function(index,item){
                p.data[item.name] = item.value ;
            });
            p.data.page = p.page;
            p.data.page_nums = p.num;
            return p.data;
        }

    })


</script>